package service

import (
	"day12_11_homework/config"
	"day12_11_homework/internal/models/dao"
)

func Register(user *dao.User) error {
	return config.DB.Model(&dao.User{}).Create(&user).Error
}

func Login(tel string) (user *dao.User, err error) {
	err = config.DB.Model(&dao.User{}).Where("tel=?", tel).Limit(1).Find(&user).Error
	return
}

func UpdateStatus(id int) error {
	return config.DB.Model(&dao.User{}).Where("id=?", id).Update("status", 2).Error
}

func DelUser(id int) string {
	err := config.DB.Model(&dao.User{}).Where("id=?", id).Delete(&dao.User{}).Error
	if err != nil {
		return "删除失败"
	}
	return ""
}
